<?php use_stylesheet('flexigrid_table') ?>
<?php use_javascript('/js/json_parse.js') ?>
<fieldset>
	<h1><?php echo $mainReportDef['title']?></h1>
	<h3><?php echo $mainReportDef['description']?></h3>
	<?php echo nl2br($mainReportDef['commentaire']) ?>

</fieldset>
<?php include_partial('formParameters', array('form' => $form,'dom'=>$doc)) ?>
<!-- 
<div id="reportPrintButton">
<a href="#" onclick="window.print();return false;"><img src="/images/icons/48/print.png" title="<?php echo __('Print')?>"></a>
</div>
 -->
<div style="clear:both"></div>
<div id = "DivIdToPrint">
<?php if(strtolower($mainReportDef['type'])=='grid'):?>
		<?php include_partial('reports/gridReport', array('reportdef' => $mainReportDef,'dom'=>$doc));?>
<?php elseif(($mainReportDef['type'])=='crossTable' or strtolower($mainReportDef['type'])=='table'):?>	
		<?php include_partial('reports/crosstableReport', array('reportdef' => $mainReportDef,'dom'=>$doc));?>
<?php elseif(strtolower($mainReportDef['type'])=='graph' or strtolower($mainReportDef['type'])=='chart'):?>	
		<?php include_partial('reports/graph', array('reportdef' => $mainReportDef,'dom'=>$doc));?>
<?php elseif(strtolower($mainReportDef['type'])=='jasperreport'):?>	
		<?php include_partial('reports/jasperReport', array('reportdef' => $mainReportDef,'dom'=>$doc));?>
<?php elseif(strtolower($mainReportDef['type'])=='download_xls'):?>	
		<?php include_partial('reports/downloadReport', array('reportdef' => $mainReportDef,'dom'=>$doc));?>
<?php elseif($mainReportDef['type']=='dashboard'):?>


	<fieldset id="reportcontent">
		<div id="sections" style="width: 100% ; float: left; display:none">
		<?php foreach($mainReportDef['sections'] as $xmlDef):?>
			<?php
				$code = $xmlDef->getAttribute('code');
				$width = $xmlDef->getAttribute('width');
				if(empty($width)) $width = '100%';
				$position = $xmlDef->getAttribute('position');
				if(empty($position)) $position = 'none';
				$style = $xmlDef->getAttribute('style');
				if(empty($style)) $style = '';
				$hideTitle = false;
				if($xmlDef->hasAttribute('hideTitle')){
					$hideTitle = (strtolower($xmlDef->getAttribute('hideTitle'))=='true') ? true: false;
				}
				$hideDescription = false;
				if($xmlDef->hasAttribute('hideDescription')){
					$hideDescription = (strtolower($xmlDef->getAttribute('hideDescription'))=='true') ? true: false;
				}
				$hideCommentaire = false;
				if($xmlDef->hasAttribute('hideCommentaire')){
					$hideCommentaire = (strtolower($xmlDef->getAttribute('hideCommentaire'))=='true') ? true: false;
				}
				
				$report = $boardReports[$code];
			?>
			<div class="section" id="section_<?php echo $report['code']?>" style="width:<?php echo $width;?>;float:<?php echo $position;?>;<?php echo $style;?>">
			 <?php if($report['code']!='separator'):?>
			 	<?php if(!$hideTitle):?>
				<h1><?php echo $report['title']?></h1>
				<?php endif?>
				<?php if(!$hideDescription):?>
				<h3><?php echo $report['description']?></h3>
				<?php endif; ?>
				<?php if(!$hideCommentaire):?>
				<?php echo nl2br($report['commentaire']) ?>
				<?php endif;?>
				<?php if(strtolower($report['type'])=='grid'):?>
						<?php include_partial('reports/gridReport', array('reportdef' => $report,'dom'=>$doc));?>
			  	<?php elseif(strtolower($report['type'])=='crosstable' or strtolower($report['type'])=='table'):?>
					  		<?php include_partial('reports/crosstableReport', array('reportdef' => $report,'dom'=>$doc));?>
			  	<?php elseif(strtolower($report['type'])=='chart' or strtolower($report['type'])=='graph'):?>
					  		<?php include_partial('reports/graph', array('reportdef' => $report,'dom'=>$doc));?>
			  	<?php elseif(strtolower($report['type'])=='template' or strtolower($report['type'])=='graph'):?>
					  		<?php include_partial('reports/templateReport', array('reportdef' => $report,'dom'=>$doc));?>
			  	<?php endif;?>
			  <?php endif;?>	
			</div>
		<?php endforeach;?>
		</div>
	</fieldset>
<?php endif;?>
<?php if($mainReportDef['type']=='chart' or $mainReportDef['type']=='graph'):?>
	<?php include_partial('reports/graph', array('reportdef' => $mainReportDef,'dom'=>$doc));?>
<?php endif;?>	
</div>

<script type="text/javascript">
<?php echo $reportDef['javascript'] ?>
</script>

<script type="text/javascript">
function refresh(){
	var result = tmt.validator.validateForm("paramsForm");
	if(result){
		if(typeof reportPreExec === 'function'){
			reportPreExec();
		}
			
<?php 
if(strtolower($mainReportDef['type'])=='dashboard'):
	foreach($boardReports as $report):
		if($report['code']!='separator'){
			if(strtolower($report['type'])=='graph' or strtolower($report['type'])=='chart'){
				echo  'refreshChart'. $report['id'] . '();' ;
			}else{
				echo  'refresh'. $report['id'] . '();' ;
			}
		}
	endforeach;?>
		document.getElementById('sections').style.display='block';
<?php elseif(strtolower($mainReportDef['type'])=='graph' or strtolower($mainReportDef['type'])=='chart'):
	echo  'refreshChart'. $mainReportDef['id'] . '();' ;
else:
	echo  'refresh'. $mainReportDef['id'] . '();' ;
	if(isset($mainReportDef['showDefaultChart'])):
		if($mainReportDef['showDefaultChart']):
			echo  'refreshChart'. $mainReportDef['id'] . '();' ;
		endif;
	endif;
endif;
?>
	if(typeof reportPostExec === 'function'){
		reportPostExec();
	}
	}
}
</script>